#include "test-module-item-manager.h"

TestModuleItemManager::TestModuleItemManager(/* args */)
{
    frame_format.register_recv_command_data_callback(std::bind(&TestModuleItemManager::recv_command_data_assign, this, std::placeholders::_1));
}

TestModuleItemManager::~TestModuleItemManager()
{
}

int TestModuleItemManager::recv_command_data(void *data, uint16_t length)
{
    //判断入参合法性
    if(NULL == data)
    {
        printf("传入参数错误！\n");
        return -1;
    }
    
    frame_format.frame_analysis_function(data, length);

    return 0;
}

int TestModuleItemManager::recv_command_data_assign(TestModuleFrameContent data)
{
    if(NULL == data.data)
    {
        return -1;
    }
    //创建数据保存空间
    uint8_t command_data[data.data_length];
    //获取数据
    memcpy(command_data, data.data, data.data_length);
    //释放申请的空间
    delete data.data;
    //根据数据中的命令值选取对应的测试项并传递数据内容
    printf("test type %x\n", command_data[0]);
    switch (command_data[0])
    {
    
    case TEST_INFRARED_LAMP:
        infrared_lamp.recv_command_data(command_data, data.data_length);
        break;
    case TEST_MICROPHONE:
        microphone.recv_command_data(command_data, data.data_length);
        break;
    case TEST_SPEAKER:
        speaker.recv_command_data(command_data, data.data_length);
        break;
    case TEST_CAMERA_MODULE:
        camera_module.recv_command_data(command_data, data.data_length);
        break;
    case TEST_WIFI_CONNECT:
        wifi_connect.recv_command_data(command_data, data.data_length);
        break;
    case TEST_AUDIO_CABLE_INSERT:
        audio_cable_insert.recv_command_data(command_data, data.data_length);
        break;
    case TEST_MODE_BUTTON:
        mode_button.recv_command_data(command_data, data.data_length);
        break;
    case TEST_PTT_BUTTON:
        ptt_button.recv_command_data(command_data, data.data_length);
        break;
    case TEST_LIP_RECOGNITION:
        lip_recognition.recv_command_data(command_data, data.data_length);
        break;
    default:
        printf("test type %x\n", command_data[0]);
        break;
    }

    return 0;
}
